package com.hogocloud.corelibrary.http;


import com.hogocloud.corelibrary.base.BaseResponse;

import io.reactivex.functions.Function;

/**
 * 处理服务器返回的数据 去壳
 *
 * @author gjc
 * @version 1.0.0
 * @since 2018-10-10
 */

public class ServerResponseFunc<T> implements Function<BaseResponse<T>, T> {

    @Override
    public T apply(BaseResponse<T> response) {
        if (!response.getSuccess()) {
            throw new ServerException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }
}
